package cn.edu.hzw.criminalintent.model

import androidx.lifecycle.LiveData
import androidx.lifecycle.MutableLiveData
import androidx.lifecycle.Transformations
import androidx.lifecycle.ViewModel
import cn.edu.hzw.criminalintent.CrimeRepository
import cn.edu.hzw.criminalintent.bean.Crime
import java.io.File
import java.util.*

/**
 * 数据转换
 */
class CrimeDetailViewModel:ViewModel() {
    private val crimeRepository = CrimeRepository.get()
    private val crimeIdLiveData = MutableLiveData<UUID>()
    var crimeLiveData : LiveData<Crime?> = Transformations.switchMap(crimeIdLiveData){
        crimeId ->
        crimeRepository.getCrime(crimeId)
    }
    fun loadCrime(crimeId:UUID){
        crimeIdLiveData.value = crimeId
    }
    fun saveCrime(crime:Crime){
        crimeRepository.updateCrime(crime)
    }
    fun getPhotoFile(crime:Crime):File{
        return crimeRepository.getPhotoFile(crime)
    }
}